﻿namespace CodeBetter.Extensions
{
    using System.Runtime.Remoting.Messaging;
    using System.Web;

    public class ThreadSafeStorage
    {
        public static void SetData(string key, object value)
        {
            if (HttpContext.Current != null)
            {
                HttpContext.Current.Items.Add(key, value);
            }
            else
            {
                CallContext.SetData(key, value);
            }
        }
        public static T GetData<T>(string key)
        {
            if (HttpContext.Current != null)
            {
                return (T)HttpContext.Current.Items[key];
            }
            return (T)CallContext.GetData(key);
        }
    }
}
